﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FinalProject.Services.Interfaces;
using FinalProject.Web.ViewModels;

namespace FinalProject.Web.Controllers
{
    public class HomeController : Controller
    {
        private readonly IClientService _clientService;

        public HomeController(IClientService clientService)
        {
            _clientService = clientService;
        }

        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";

            var homeViewModel = new HomeViewModel();
            homeViewModel.Clients = _clientService.GetLastAccessedClients(10).ToList();
            return View(homeViewModel);
        }

        public ActionResult FindClients(string search)
        {
            var clients = _clientService.SearchClient(search).Entities.ToArray();
            var temp = new List<String>();
            foreach (var client in clients)
                temp.Add(client.PersonName.FirstName);
            return Json(temp.ToArray());
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
